import { Context } from "../class/Context";
import { Hurt } from "../class/Hurt";
import { Method } from "../class/Method";
import { Role } from "../class/Role";

/**
 * 化羽归尘
 */
export class HuaYuGuiChen extends Method {
    static methodName = "化羽归尘"
    public CD: number = 20E3;
    public describe: string = "化羽为盾守护自身，反弹对方攻击，对攻击者造成同等伤害.";
    invoke(context: Context): void {
        // 旧的方法
        const oldOnHurt = this.masterRole.onHurt

        this.masterRole.onHurt = function (role: Role, hurt: Hurt) {
            role.onHurt(this, hurt); // 反弹伤害
            over(); // 移除反弹机制
            clearTimeout(T);// 移除自动设置

            return 0;
        }

        // 返回一个定时器种子
        const T = setTimeout(() => over(), 10E3);// 10 * 1000

        // 移除反弹机制
        const over = () => {
            this.masterRole.onHurt = oldOnHurt;
        }
    }
}